<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<!-- modify by zhangwei -->
<!-- 百度站长 -->
<meta name="baidu-site-verification" content="MdPKZBgY0U">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">



  <meta name="google-site-verification" content="8DKRuNxJDPU2k6cNyVhLe_eSqGk-R8oiYk8iKMg5gwI">














  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/uploads/favicon.ico?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/uploads/favicon.ico?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/uploads/favicon.ico?v=5.1.4">


  <link rel="mask-icon" href="/uploads/favicon.ico?v=5.1.4" color="#222">





  <meta name="keywords" content="Android,SQLite,GreenDao,">





  <link rel="alternate" href="/atom.xml" title="班德尔城" type="application/atom+xml">






<meta name="description" content="GreenDao 是一个将对象映射到 SQLite 数据库中的轻量且快速的 ORM 解决方案。它的本质就是提供一个面向对象的接口，使得开发者更加方便地将数据存储到数据库SQLite之中。我们只需要定义数据模型，GreenDao就会为我们生成实体类以及DAOs(data access objects)，（在3.0之后不需要我们编写generator而是编写实体类并添加注解，GreenDao会为我们">
<meta name="keywords" content="Android,SQLite,GreenDao">
<meta property="og:type" content="article">
<meta property="og:title" content="Android白银篇-GreenDao3">
<meta property="og:url" content="https://tiimor.cn/Android白银篇-GreenDao3/index.html">
<meta property="og:site_name" content="班德尔城">
<meta property="og:description" content="GreenDao 是一个将对象映射到 SQLite 数据库中的轻量且快速的 ORM 解决方案。它的本质就是提供一个面向对象的接口，使得开发者更加方便地将数据存储到数据库SQLite之中。我们只需要定义数据模型，GreenDao就会为我们生成实体类以及DAOs(data access objects)，（在3.0之后不需要我们编写generator而是编写实体类并添加注解，GreenDao会为我们">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://cdn.tiimor.cn/images/GreenDao.png">
<meta property="og:image" content="http://cdn.tiimor.cn/images/GreenDao-%E5%8D%95%E4%BD%8D%E6%97%B6%E9%97%B4%E5%86%85%E7%9A%84%E6%93%8D%E4%BD%9C%E6%95%B0%E9%87%8F.png">
<meta property="og:updated_time" content="2019-03-17T06:47:42.367Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Android白银篇-GreenDao3">
<meta name="twitter:description" content="GreenDao 是一个将对象映射到 SQLite 数据库中的轻量且快速的 ORM 解决方案。它的本质就是提供一个面向对象的接口，使得开发者更加方便地将数据存储到数据库SQLite之中。我们只需要定义数据模型，GreenDao就会为我们生成实体类以及DAOs(data access objects)，（在3.0之后不需要我们编写generator而是编写实体类并添加注解，GreenDao会为我们">
<meta name="twitter:image" content="http://cdn.tiimor.cn/images/GreenDao.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '3AUIZWGETM',
      apiKey: '5fcd6d51d892fffe3480c5b37f5fd4fa',
      indexName: 'Tiimor',
      hits: {"per_page":8},
      labels: {"input_placeholder":"搜索","hits_empty":"未发现与「${query}」相关的内容","hits_stats":"${hits} 条相关条目，使用了 ${time} 毫秒"}
    }
  };
</script>



  <link rel="canonical" href="https://tiimor.cn/Android白银篇-GreenDao3/">





  <title>Android白银篇-GreenDao3 | 班德尔城</title>
  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-96457043-1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?abb97f8f68c9e5eb2217d3111c64e696";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

  <!-- modify by zhangwei -->
  <!-- 下雪的动画 -->
  <div class="canvas-snow">
    <canvas id="canvas" style="margin: 0;  padding: 0;top:0; left: 0; right: 0; background: transparent; position: absolute;" width="1366" height="105"></canvas>
      <script>

      var canvasBgImg = {
        start: function () {
          this.canvas = document.getElementById('canvas')
          this.ctx = this.canvas.getContext("2d")
          this.canvas.width = window.innerWidth
          this.canvas.height = 105
          this.starList = []
        },
        drawLine: function (ctx, x1, y1, x2, y2) {
          ctx.beginPath()
          ctx.strokeStyle = '#ffffff'
          ctx.lineTo(x1, y1)
          ctx.lineTo(x2, y2)
          ctx.stroke()
        },
        canvasSingleSnow: function (snowSize) {
          var singleSnow = document.createElement('canvas'),
            ctxSingle = singleSnow.getContext('2d')
          singleSnow.setAttribute('width', snowSize * 2)
          singleSnow.setAttribute('height', snowSize * 2)
          for (var i = 0; i < 6; i++) {
            ctxSingle.save()
            ctxSingle.translate(snowSize, snowSize)
            ctxSingle.rotate(Math.PI * 2 * i / 6)
            this.drawLine(ctxSingle, 0, 0, snowSize, 0)
            ctxSingle.restore()
          }
          return singleSnow
        },
        canvasAllSnow: function (centerSnow) {
          var canvasSnow = document.createElement('canvas'),
            ctxSnow = canvasSnow.getContext('2d'),
            bigSnow = this.canvasSingleSnow(centerSnow),
            smallSnow = this.canvasSingleSnow(centerSnow / 3),
            sizeSnow = centerSnow * 3 / 5,
            rSnow = centerSnow - sizeSnow / 2
          canvasSnow.setAttribute('width', centerSnow * 2)
          canvasSnow.setAttribute('height', centerSnow * 2)
          ctxSnow.drawImage(bigSnow, 0, 0, bigSnow.width, bigSnow.height, 0, 0, centerSnow * 2, centerSnow * 2)
          for (var i = 0; i < 6; i++) {
            ctxSnow.save()
            ctxSnow.translate(centerSnow, centerSnow)
            ctxSnow.rotate(Math.PI * 2 * i / 6)
            ctxSnow.drawImage(smallSnow, 0, 0, smallSnow.width, smallSnow.height, rSnow - sizeSnow / 2,
              -sizeSnow / 2, sizeSnow, sizeSnow)
            ctxSnow.restore()
          }
          return canvasSnow
        },
        init: function () {
          this.start()
          for (var i = 0; i < 75; i++) {
            this.starList.push({
              drawFunc: this.canvasAllSnow(15),
              width: Math.random() * this.canvas.width,
              height: Math.random() * this.canvas.height,
              speed: Math.random() * 1.5 + .5,
              scale: Math.random() * 12 + 5,
              angel: 0
            })
          }
          var self = this,
            loop = function () {
              self.ctx.clearRect(0, 0, self.canvas.width, self.canvas.width)
              for (var i = 0; i < 75; i++) {
                self.ctx.save()
                self.starList[i].height = self.starList[i].height + self.starList[i].speed
                self.starList[i].angel += 2
                self.ctx.translate(self.starList[i].width, self.starList[i].height)
                self.ctx.rotate(self.starList[i].angel * Math.PI / 360)
                self.ctx.translate(-self.starList[i].width, -self.starList[i].height)
                self.ctx.drawImage(self.starList[i].drawFunc, 0, 0,
                  self.starList[i].drawFunc.width, self.starList[i].drawFunc.height,
                  self.starList[i].width - self.starList[i].scale / 2,
                  self.starList[i].height - self.starList[i].scale / 2,
                  self.starList[i].scale, self.starList[i].scale)
                if (self.starList[i].height > self.canvas.height) {
                  self.starList[i] = Object.assign(self.starList[i], {
                    height: -self.starList[i].scale,
                    width: Math.random() * this.canvas.width
                  })
                }
                self.ctx.restore()
              }
              requestAnimationFrame(loop)
            }
          requestAnimationFrame(loop)
        }
      }
      canvasBgImg.init()
      </script>

    </div>


    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <!-- modify by zhangwei -->
        <!-- 圣诞帽 -->
        <img src="/uploads/santa-hat.png" id="santa" style="height: 41px; position: absolute; left: -40px; top: -20px; transform: rotate(-45deg); z-index: 9000;">

        <span class="logo-line-before"><i></i></span>
        <span class="site-title">班德尔城</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">微笑，简单，奋发</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-guestbook">
          <a href="/guestbook" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-send"></i> <br>
            
            留言
          </a>
        </li>
      
        
        <li class="menu-item menu-item-favourite">
          <a href="/favourite" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-bookmark"></i> <br>
            
            收藏
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  
  <div class="algolia-popup popup search-popup">
    <div class="algolia-search">
      <div class="algolia-search-input-icon">
        <i class="fa fa-search"></i>
      </div>
      <div class="algolia-search-input" id="algolia-search-input"></div>
    </div>

    <div class="algolia-results">
      <div id="algolia-stats"></div>
      <div id="algolia-hits"></div>
      <div id="algolia-pagination" class="algolia-pagination"></div>
    </div>

    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
  </div>




    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://tiimor.cn/Android白银篇-GreenDao3/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Tiimor">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/uploads/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="班德尔城">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Android白银篇-GreenDao3</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-11-04T16:34:52+08:00">
                2017-11-04
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Android联盟/" itemprop="url" rel="index">
                    <span itemprop="name">Android联盟</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/Android白银篇-GreenDao3/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count gitment-comments-count" data-xid="/Android白银篇-GreenDao3/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/Android白银篇-GreenDao3/" class="leancloud_visitors" data-flag-title="Android白银篇-GreenDao3">
               <span class="post-meta-divider">|</span>
               <!-- modify by zhangwei -->
               <!-- 去掉阅读的眼睛图标，阅读次数改为℃ -->
			   
                 <span class="post-meta-item-text">热度 </span>
               
                 <span class="leancloud-visitors-count"></span>
				 <span>℃</span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><img src="http://cdn.tiimor.cn/images/GreenDao.png" alt="GreenDao"></p>
<p>GreenDao &#x662F;&#x4E00;&#x4E2A;&#x5C06;&#x5BF9;&#x8C61;&#x6620;&#x5C04;&#x5230; SQLite &#x6570;&#x636E;&#x5E93;&#x4E2D;&#x7684;&#x8F7B;&#x91CF;&#x4E14;&#x5FEB;&#x901F;&#x7684; ORM &#x89E3;&#x51B3;&#x65B9;&#x6848;&#x3002;&#x5B83;&#x7684;&#x672C;&#x8D28;&#x5C31;&#x662F;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x9762;&#x5411;&#x5BF9;&#x8C61;&#x7684;&#x63A5;&#x53E3;&#xFF0C;&#x4F7F;&#x5F97;&#x5F00;&#x53D1;&#x8005;&#x66F4;&#x52A0;&#x65B9;&#x4FBF;&#x5730;&#x5C06;&#x6570;&#x636E;&#x5B58;&#x50A8;&#x5230;&#x6570;&#x636E;&#x5E93;SQLite&#x4E4B;&#x4E2D;&#x3002;&#x6211;&#x4EEC;&#x53EA;&#x9700;&#x8981;&#x5B9A;&#x4E49;&#x6570;&#x636E;&#x6A21;&#x578B;&#xFF0C;GreenDao&#x5C31;&#x4F1A;&#x4E3A;&#x6211;&#x4EEC;&#x751F;&#x6210;&#x5B9E;&#x4F53;&#x7C7B;&#x4EE5;&#x53CA;DAOs(data access objects)&#xFF0C;&#xFF08;&#x5728;3.0&#x4E4B;&#x540E;&#x4E0D;&#x9700;&#x8981;&#x6211;&#x4EEC;&#x7F16;&#x5199;generator&#x800C;&#x662F;&#x7F16;&#x5199;&#x5B9E;&#x4F53;&#x7C7B;&#x5E76;&#x6DFB;&#x52A0;&#x6CE8;&#x89E3;&#xFF0C;GreenDao&#x4F1A;&#x4E3A;&#x6211;&#x4EEC;&#x751F;&#x6210;schema&#xFF0C;&#x4EE5;&#x53CA;DAOs&#xFF09;&#x4ECE;&#x800C;&#x907F;&#x514D;&#x4E86;&#x5F00;&#x53D1;&#x8005;&#x7F16;&#x5199;&#x8F83;&#x591A;&#x67AF;&#x71E5;&#x7684;&#x6570;&#x636E;&#x5B58;&#x50A8;&#x548C;&#x52A0;&#x8F7D;&#x7684;&#x4EE3;&#x7801;&#x3002;</p>
<a id="more"></a>
<hr>
<blockquote>
<ul>
<li><a href="http://tiimor.cn/Android%E9%BB%84%E9%87%91%E7%AF%87-SQLite%E6%95%B0%E6%8D%AE%E5%BA%93/">Android&#x9EC4;&#x91D1;&#x7BC7;-SQLite&#x6570;&#x636E;&#x5E93;</a></li>
<li><a href="http://tiimor.cn/Android%E6%95%B0%E6%8D%AE%E5%BA%93%E5%8A%A0%E5%AF%86/">Android&#x6570;&#x636E;&#x5E93;&#x52A0;&#x5BC6;</a></li>
</ul>
</blockquote>
<hr>
<font size="4"><strong><a href="https://github.com/greenrobot/greenDAO" target="_blank" rel="noopener">GreenDao&#x4F20;&#x9001;&#x95E8;</a></strong></font>

<p><br></p>
<h1 id="GreenDao&#x4ECB;&#x7ECD;"><a href="#GreenDao&#x4ECB;&#x7ECD;" class="headerlink" title="GreenDao&#x4ECB;&#x7ECD;"></a>GreenDao&#x4ECB;&#x7ECD;</h1><p>&#x5728;GreenDao&#x4E2D;&#xFF0C;&#x9ED8;&#x8BA4;&#x4F1A;&#x4E3A;&#x6BCF;&#x4E00;&#x4E2A;&#x5B9E;&#x4F53;&#x7C7B;&#x5EFA;&#x7ACB;&#x4E00;&#x5F20;&#x6570;&#x636E;&#x8868;&#xFF0C;&#x5B9E;&#x4F53;&#x7C7B;&#x7684;&#x6BCF;&#x4E00;&#x4E2A;&#x5C5E;&#x6027;&#x5BF9;&#x5E94;&#x6570;&#x636E;&#x8868;&#x4E2D;&#x7684;&#x4E00;&#x5217;&#x3002;</p>
<p><strong>&#x4F18;&#x70B9;</strong></p>
<ul>
<li>Android&#x7CBE;&#x7B80;&#x7684;&#x4F9D;&#x8D56;&#x5E93;&#xFF0C;&#x65B9;&#x4FBF;&#x96C6;&#x6210;</li>
<li>&#x6027;&#x80FD;&#x6700;&#x5927;&#x5316;</li>
<li>&#x5185;&#x5B58;&#x5F00;&#x9500;&#x6700;&#x5C0F;&#x5316;</li>
<li>&#x6613;&#x4E8E;&#x4F7F;&#x7528;&#x7684;APIs</li>
<li>&#x5BF9;Android&#x8FDB;&#x884C;&#x9AD8;&#x5EA6;&#x4F18;&#x5316;</li>
</ul>
<p><img src="http://cdn.tiimor.cn/images/GreenDao-%E5%8D%95%E4%BD%8D%E6%97%B6%E9%97%B4%E5%86%85%E7%9A%84%E6%93%8D%E4%BD%9C%E6%95%B0%E9%87%8F.png" alt="&#x6027;&#x80FD;&#x6BD4;&#x8F83;" title="&#x5355;&#x4F4D;&#x65F6;&#x95F4;&#x5185;&#x7684;&#x64CD;&#x4F5C;&#x6570;&#x91CF;"></p>
<h1 id="&#x914D;&#x7F6E;"><a href="#&#x914D;&#x7F6E;" class="headerlink" title="&#x914D;&#x7F6E;"></a>&#x914D;&#x7F6E;</h1><p>GreenDao3 &#x91C7;&#x7528;&#x6CE8;&#x89E3;&#x65B9;&#x5F0F;&#x6765;&#x5B9A;&#x4E49;&#x5B9E;&#x4F53;&#x7C7B;&#xFF0C;&#x901A;&#x8FC7;gradle&#x63D2;&#x4EF6;&#x751F;&#x6210;&#x76F8;&#x5E94;&#x7684;&#x4EE3;&#x7801;&#x3002;</p>
<h2 id="&#x914D;&#x7F6E;&#x63D2;&#x4EF6;"><a href="#&#x914D;&#x7F6E;&#x63D2;&#x4EF6;" class="headerlink" title="&#x914D;&#x7F6E;&#x63D2;&#x4EF6;"></a>&#x914D;&#x7F6E;&#x63D2;&#x4EF6;</h2><p>&#x5728;&#x5DE5;&#x7A0B;<strong>&#x6839;&#x76EE;&#x5F55;&#x4E0B;&#x7684;build.gradle&#x6587;&#x4EF6;&#x91CC;</strong>&#xFF0C;&#x6DFB;&#x52A0;&#x4EE3;&#x7801;&#xFF1A;<br></p><figure class="highlight gradle"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">dependencies</span> {</span><br><span class="line">	<span class="keyword">classpath</span> <span class="string">&apos;com.android.tools.build:gradle:2.3.3&apos;</span></span><br><span class="line">	<span class="comment">// &#x6DFB;&#x52A0;GreenDao&#x63D2;&#x4EF6;	</span></span><br><span class="line">	<span class="keyword">classpath</span> <span class="string">&apos;org.greenrobot:greendao-gradle-plugin:3.2.0&apos;</span></span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><p></p>
<h2 id="&#x914D;&#x7F6E;&#x4F9D;&#x8D56;"><a href="#&#x914D;&#x7F6E;&#x4F9D;&#x8D56;" class="headerlink" title="&#x914D;&#x7F6E;&#x4F9D;&#x8D56;"></a>&#x914D;&#x7F6E;&#x4F9D;&#x8D56;</h2><p>&#x5728;<strong>Module&#x4E0B;&#x7684;build.gradle</strong>&#x6587;&#x4EF6;&#x91CC;&#xFF0C;&#x6DFB;&#x52A0;&#x4EE3;&#x7801;&#xFF1A;<br></p><figure class="highlight sqf"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">apply</span> plugin: <span class="string">&apos;com.android.application&apos;</span></span><br><span class="line"><span class="comment">// &#x6DFB;&#x52A0;</span></span><br><span class="line"><span class="built_in">apply</span> plugin: <span class="string">&apos;org.greenrobot.greendao&apos;</span></span><br><span class="line"></span><br><span class="line">dependencies {</span><br><span class="line">	<span class="comment">// &#x6DFB;&#x52A0;</span></span><br><span class="line">	<span class="built_in">compile</span> <span class="string">&apos;org.greenrobot:greendao:3.2.0&apos;</span></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">// &#x6DFB;&#x52A0;</span></span><br><span class="line">greendao {</span><br><span class="line">    schemaVersion <span class="number">1</span></span><br><span class="line">    daoPackage <span class="string">&apos;com.excellence.medical.greendao&apos;</span></span><br><span class="line">    targetGenDir <span class="string">&apos;src/main/java&apos;</span></span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><p></p>
<ul>
<li>schemaVersion&#xFF1A; &#x6570;&#x636E;&#x5E93;&#x7248;&#x672C;&#x53F7;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;1</li>
<li>daoPackage&#xFF1A; &#x751F;&#x6210;&#x7684;DAOs&#x3001;DaoMaster&#x3001;DaoSession&#x5305;&#x540D;&#xFF1B;&#x9ED8;&#x8BA4;&#x4E3A;entities&#xFF08;&#x6570;&#x636E;&#x5E93;&#x5B9E;&#x4F53;&#x7C7B;&#xFF09;&#x6240;&#x5728;&#x7684;&#x5305;&#x540D;</li>
<li>targetGenDir: &#x751F;&#x6210;&#x7684;DAOs&#x3001;DaoMaster&#x3001;DaoSession&#x7684;&#x76EE;&#x5F55;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;build/generated/source/greendao</li>
<li>generateTests: &#x8BBE;&#x7F6E;true&#x81EA;&#x52A8;&#x751F;&#x6210;&#x5355;&#x5143;&#x6D4B;&#x8BD5;&#x3002;</li>
<li>targetGenDirTests: &#x8BBE;&#x7F6E;&#x751F;&#x6210;&#x5355;&#x5143;&#x6D4B;&#x8BD5;&#x76EE;&#x5F55;&#x3002;&#x9ED8;&#x8BA4;&#x4E3A;src/androidTest/java</li>
</ul>
<h1 id="&#x57FA;&#x672C;&#x7528;&#x6CD5;"><a href="#&#x57FA;&#x672C;&#x7528;&#x6CD5;" class="headerlink" title="&#x57FA;&#x672C;&#x7528;&#x6CD5;"></a>&#x57FA;&#x672C;&#x7528;&#x6CD5;</h1><h2 id="&#x5B9E;&#x4F53;"><a href="#&#x5B9E;&#x4F53;" class="headerlink" title="&#x5B9E;&#x4F53;"></a>&#x5B9E;&#x4F53;</h2><p>&#x521B;&#x5EFA;&#x5E26;&#x6CE8;&#x89E3;@Entity&#x7684;&#x5B9E;&#x4F53;&#x7C7B;&#xFF0C;&#x5B9E;&#x4F53;&#x7C7B;&#x5373;&#x6570;&#x636E;&#x8868;&#xFF1B;&#x901A;&#x5E38;&#xFF08;&#x9664;&#x5F00;&#x5E26;@Transient&#x6CE8;&#x89E3;&#x7684;&#x6210;&#x5458;&#xFF09;&#x5B9E;&#x4F53;&#x7C7B;&#x4E2D;&#x6210;&#x5458;&#x5C31;&#x662F;&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x5BF9;&#x5E94;&#x7684;&#x5B57;&#x6BB5;&#x3002;&#x7136;&#x540E;<code>make project</code>&#x7F16;&#x8BD1;&#x9879;&#x76EE;&#xFF0C;&#x5B9E;&#x4F53;&#x7C7B;&#x4F1A;&#x81EA;&#x52A8;&#x751F;&#x6210;get&#x3001;set&#x65B9;&#x6CD5;&#xFF0C;&#x5E76;&#x4E14;&#x5728;<code>targetGenDir</code>&#x76EE;&#x5F55;&#x4E0B;&#x7684;<code>daoPackage</code>&#x5305;&#x91CC;&#xFF0C;&#x5982;<code>src/main/java/com/excellence/medical/greendao</code>&#xFF0C;&#x751F;&#x6210;DaoMaster&#x3001;DaoSession&#x3001;&#x4EE5;&#x53CA;AccountDao&#x3002;</p>
<p>&#x5982;&#x679C;&#x60F3;&#x589E;&#x52A0;&#x6216;&#x51CF;&#x5C11;&#x6570;&#x636E;&#x5E93;&#x5B57;&#x6BB5;&#xFF0C;&#x5220;&#x9664;&#x5B9E;&#x4F53;&#x7C7B;&#x4E2D;&#x81EA;&#x52A8;&#x751F;&#x6210;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x7136;&#x540E;&#x8FDB;&#x884C;&#x589E;&#x52A0;&#x6216;&#x51CF;&#x5C11;&#x5B9E;&#x4F53;&#x7C7B;&#x4E2D;&#x7684;&#x6210;&#x5458;&#x3002;</p>
<figure class="highlight kotlin"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Entity(nameInDb = <span class="meta-string">&quot;account&quot;</span>)</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Account</span> </span>{</span><br><span class="line"></span><br><span class="line">	<span class="meta">@Id(autoincrement = true)</span></span><br><span class="line">	<span class="keyword">private</span> <span class="built_in">Long</span>			id;</span><br><span class="line">	<span class="meta">@Unique</span></span><br><span class="line">	<span class="keyword">private</span> String			accountId;</span><br><span class="line">	<span class="keyword">private</span> String			accountName;</span><br><span class="line">	<span class="keyword">private</span> String			accountPwd;</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
<h2 id="&#x6CE8;&#x89E3;"><a href="#&#x6CE8;&#x89E3;" class="headerlink" title="&#x6CE8;&#x89E3;"></a>&#x6CE8;&#x89E3;</h2><ul>
<li><p>@Entity<br>&#x4FEE;&#x9970;&#x5B9E;&#x4F53;&#x7C7B;&#x540D;</p>
<figure class="highlight nix"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">@Entity(</span><br><span class="line">    // schema &#x540D;&#xFF0C;&#x591A;&#x4E2A; schema &#x65F6;&#x8BBE;&#x7F6E;&#x5173;&#x8054;&#x5B9E;&#x4F53;&#x3002;&#x63D2;&#x4EF6;&#x4EA7;&#x751F;&#x4E0D;&#x652F;&#x6301;&#xFF0C;&#x9700;&#x4F7F;&#x7528;&#x4EA7;&#x751F;&#x5668;</span><br><span class="line">    // <span class="attr">schema</span> = <span class="string">&quot;myschema&quot;</span>,</span><br><span class="line"></span><br><span class="line">    // &#x6807;&#x8BB0;&#x4E00;&#x4E2A;&#x5B9E;&#x4F53;&#x662F;&#x5426;&#x5904;&#x4E8E;&#x6D3B;&#x52A8;&#x72B6;&#x6001;&#xFF0C;&#x6D3B;&#x52A8;&#x5B9E;&#x4F53;&#x6709; update&#x3001;delete&#x3001;refresh &#x65B9;&#x6CD5;&#x3002;&#x9ED8;&#x8BA4;&#x4E3A; <span class="literal">false</span></span><br><span class="line">    <span class="attr">active</span> = <span class="literal">false</span>,</span><br><span class="line"></span><br><span class="line">    // &#x8868;&#x540D;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;&#x7C7B;&#x540D;</span><br><span class="line">    <span class="attr">nameInDb</span> = <span class="string">&quot;Account&quot;</span>,</span><br><span class="line"></span><br><span class="line">    // &#x5B9A;&#x4E49;&#x591A;&#x5217;&#x7D22;&#x5F15;</span><br><span class="line">    <span class="attr">indexes</span> = {</span><br><span class="line">            @Index(<span class="attr">value</span> = <span class="string">&quot;name DESC&quot;</span>, <span class="attr">unique</span> = <span class="literal">true</span>)</span><br><span class="line">    },</span><br><span class="line"></span><br><span class="line">    // &#x6807;&#x8BB0;&#x662F;&#x5426;&#x521B;&#x5EFA;&#x8868;&#xFF0C;&#x9ED8;&#x8BA4; <span class="literal">true</span>&#x3002;&#x591A;&#x5B9E;&#x4F53;&#x5BF9;&#x5E94;&#x4E00;&#x4E2A;&#x8868;&#x6216;&#x8005;&#x8868;&#x5DF2;&#x521B;&#x5EFA;&#xFF0C;&#x4E0D;&#x9700;&#x8981; greenDAO &#x521B;&#x5EFA;&#x65F6;&#x8BBE;&#x7F6E; <span class="literal">false</span></span><br><span class="line">    <span class="attr">createInDb</span> = <span class="literal">true</span>,</span><br><span class="line"></span><br><span class="line">    // &#x662F;&#x5426;&#x4EA7;&#x751F;&#x6240;&#x6709;&#x53C2;&#x6570;&#x6784;&#x9020;&#x5668;&#x3002;&#x9ED8;&#x8BA4;&#x4E3A; <span class="literal">true</span>&#x3002;&#x65E0;&#x53C2;&#x6784;&#x9020;&#x5668;&#x5FC5;&#x5B9A;&#x4EA7;&#x751F;</span><br><span class="line">    <span class="attr">generateConstructors</span> = <span class="literal">true</span>,</span><br><span class="line"></span><br><span class="line">    // &#x5982;&#x679C;&#x6CA1;&#x6709; get/set &#x65B9;&#x6CD5;&#xFF0C;&#x662F;&#x5426;&#x751F;&#x6210;&#x3002;&#x9ED8;&#x8BA4;&#x4E3A; <span class="literal">true</span></span><br><span class="line">    <span class="attr">generateGettersSetters</span> = <span class="literal">true</span></span><br><span class="line">)</span><br></pre></td></tr></tbody></table></figure>
</li>
<li><p>&#x4FEE;&#x9970;&#x5B9E;&#x4F53;&#x7C7B;&#x6210;&#x5458;</p>
<figure class="highlight less"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// &#x4E3B;&#x952E;&#xFF0C;autoincrement&#x8BBE;&#x7F6E;&#x81EA;&#x589E;&#xFF0C;&#x6CE8;&#x610F;&#x7C7B;&#x578B;&#x662F;Long&#xFF0C;&#x800C;&#x4E0D;&#x662F;long</span></span><br><span class="line"><span class="variable">@Id</span>(autoincrement = true)</span><br><span class="line"></span><br><span class="line"><span class="comment">// &#x552F;&#x4E00;&#xFF0C;&#x9ED8;&#x8BA4;&#x7D22;&#x5F15;</span></span><br><span class="line"><span class="variable">@Unique</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// &#x5217;&#x540D;-&#x5B57;&#x6BB5;&#x540D;&#xFF0C;&#x9ED8;&#x8BA4;&#x4F7F;&#x7528;&#x53D8;&#x91CF;&#x540D;&#x3002;&#x53D8;&#x5316;&#xFF1A;customName --&gt; CUSTOM_NAME</span></span><br><span class="line"><span class="variable">@Property</span>(nameInDb = <span class="string">&quot;USERNAME&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">// &#x7D22;&#x5F15;&#xFF0C;unique&#x8BBE;&#x7F6E;&#x552F;&#x4E00;&#xFF0C;name&#x8BBE;&#x7F6E;&#x7D22;&#x5F15;&#x522B;&#x540D;</span></span><br><span class="line"><span class="variable">@Index</span>(unique = true)</span><br><span class="line"></span><br><span class="line"><span class="comment">// &#x975E;&#x7A7A;</span></span><br><span class="line"><span class="variable">@NotNull</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// &#x5FFD;&#x7565;&#xFF0C;&#x4E0D;&#x6301;&#x4E45;&#x5316;&#xFF0C;&#x5373;&#x6570;&#x636E;&#x8868;&#x4E0D;&#x521B;&#x5EFA;&#x8BE5;&#x5B57;&#x6BB5;&#xFF0C;&#x53EF;&#x7528;&#x5173;&#x952E;&#x5B57;transient&#x66FF;&#x4EE3;</span></span><br><span class="line"><span class="variable">@Transient</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// &#x5BF9;&#x4E00;&#xFF0C;&#x5B9E;&#x4F53;&#x5C5E;&#x6027; joinProperty &#x5BF9;&#x5E94;&#x5916;&#x8054;&#x5B9E;&#x4F53;ID</span></span><br><span class="line"><span class="variable">@ToOne</span>(joinProperty = <span class="string">&quot;fk_dogId&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">// &#x5BF9;&#x591A;&#x3002;&#x5B9E;&#x4F53;ID&#x5BF9;&#x5E94;&#x5916;&#x8054;&#x5B9E;&#x4F53;&#x5C5E;&#x6027; referencedJoinProperty</span></span><br><span class="line"><span class="variable">@ToMany</span>(referencedJoinProperty = <span class="string">&quot;fk_userId&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">// &#x5BF9;&#x591A;&#x3002;@JoinProperty&#xFF1A;name &#x5B9E;&#x4F53;&#x5C5E;&#x6027;&#x5BF9;&#x5E94;&#x5916;&#x8054;&#x5B9E;&#x4F53;&#x5C5E;&#x6027; referencedName</span></span><br><span class="line"><span class="variable">@ToMany</span>(joinProperties = {<span class="variable">@JoinProperty</span>(name = <span class="string">&quot;horseName&quot;</span>, referencedName = <span class="string">&quot;name&quot;</span>)})</span><br><span class="line"></span><br><span class="line"><span class="comment">// &#x5BF9;&#x591A;&#x3002;@JoinEntity&#xFF1A;entity &#x4E2D;&#x95F4;&#x8868;&#xFF1B;&#x4E2D;&#x95F4;&#x8868;&#x5C5E;&#x6027; sourceProperty &#x5BF9;&#x5E94;&#x5B9E;&#x4F53;ID&#xFF1B;&#x4E2D;&#x95F4;&#x8868;&#x5C5E;&#x6027; targetProperty &#x5BF9;&#x5E94;&#x5916;&#x8054;&#x5B9E;&#x4F53;ID</span></span><br><span class="line"><span class="variable">@ToMany</span></span><br><span class="line"><span class="variable">@JoinEntity</span>(entity = JoinUserWithSheep.class, sourceProperty = <span class="string">&quot;uId&quot;</span>, targetProperty = <span class="string">&quot;sId&quot;</span>)</span><br></pre></td></tr></tbody></table></figure>
</li>
</ul>
<h2 id="&#x521D;&#x59CB;&#x5316;"><a href="#&#x521D;&#x59CB;&#x5316;" class="headerlink" title="&#x521D;&#x59CB;&#x5316;"></a>&#x521D;&#x59CB;&#x5316;</h2><p>&#x5728;Application&#x4E2D;&#x8FDB;&#x884C;&#x521D;&#x59CB;&#x5316;&#xFF0C;GreenDao&#x6253;&#x5F00;&#x6570;&#x636E;&#x5E93;&#x4E24;&#x79CD;&#x65B9;&#x5F0F;&#xFF1A;&#x2460;&#x6253;&#x5F00;&#x5185;&#x90E8;&#xFF08;<code>/data/data/xxxpackageNamexxx/</code>&#xFF09;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x2461;&#x6253;&#x5F00;&#x5916;&#x90E8;&#xFF08;&#x5176;&#x4ED6;&#x76EE;&#x5F55;&#x4E0B;&#xFF09;&#x6570;&#x636E;&#x5E93;</p>
<ul>
<li><p>&#x5185;&#x90E8;&#x6570;&#x636E;&#x5E93;</p>
<figure class="highlight haxe"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// &#x6CE8;&#x610F;</span></span><br><span class="line">DaoMaster.OpenHelper helper = <span class="keyword">new</span> <span class="type">DaoMaster</span>.DevOpenHelper(<span class="built_in">this</span>, VOD_DB, <span class="literal">null</span>);</span><br><span class="line">mDaoMaster = <span class="keyword">new</span> <span class="type">DaoMaster</span>(helper.getWritableDatabase());</span><br><span class="line"></span><br><span class="line"><span class="comment">// &#x5982;&#x679C;&#x60F3;&#x4F7F;&#x7528;Dao&#xFF0C;&#x76F4;&#x63A5;&#x7528;mDaoSession&#x83B7;&#x53D6;&#x5BF9;&#x5E94;&#x7684;Dao&#x6765;&#x64CD;&#x4F5C;</span></span><br><span class="line">mDaoSession = mDaoMaster.<span class="keyword">new</span><span class="type">Session</span>();</span><br><span class="line"><span class="comment">// Dao&#xFF0C;&#x6267;&#x884C;&#x589E;&#x5220;&#x6539;&#x67E5;&#x64CD;&#x4F5C;</span></span><br><span class="line">AccountDao dao = mDaoSession.getAccountDao();</span><br><span class="line"></span><br><span class="line"><span class="comment">// &#x5982;&#x679C;&#x60F3;&#x4F7F;&#x7528;Sql&#x8BED;&#x53E5;&#xFF0C;&#x5C31;&#x4F7F;&#x7528;mDaoDatabase&#x64CD;&#x4F5C;</span></span><br><span class="line">mDaoDatabase = mDaoSession.getDatabase();</span><br><span class="line"></span><br><span class="line"><span class="comment">// GreenDao&#x6709;&#x7279;&#x6B8A;&#x7684;&#x7EBF;&#x7A0B;&#x6765;&#x5904;&#x7406;&#x6570;&#x636E;&#x5E93;&#x7684;&#x8017;&#x65F6;&#x64CD;&#x4F5C;</span></span><br><span class="line">mAsyncSession = mDaoSession.startAsyncSession();</span><br></pre></td></tr></tbody></table></figure>
</li>
<li><p>&#x5916;&#x90E8;&#x6570;&#x636E;&#x5E93;</p>
<figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">DatabaseContext</span> <span class="keyword">extends</span> <span class="title">ContextWrapper</span> </span>{</span><br><span class="line">	</span><br><span class="line">	<span class="keyword">private</span> String mDBPath = <span class="keyword">null</span>;</span><br><span class="line">	</span><br><span class="line">	<span class="function"><span class="keyword">private</span> <span class="title">DatabaseContext</span><span class="params">(Context base)</span> </span>{</span><br><span class="line">		<span class="keyword">super</span>(base);</span><br><span class="line">	}</span><br><span class="line">	</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="title">DatabaseContext</span><span class="params">(Context base, String dbPath)</span> </span>{</span><br><span class="line">		<span class="keyword">super</span>(base);</span><br><span class="line">		mDBPath = dbPath;</span><br><span class="line">	}</span><br><span class="line">	</span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> File <span class="title">getDatabasePath</span><span class="params">(String name)</span> </span>{</span><br><span class="line">		String dbPath = mDBPath + name;</span><br><span class="line">		<span class="keyword">if</span> (FileUtils.isFileExists(dbPath)) {</span><br><span class="line">			<span class="keyword">return</span> <span class="keyword">new</span> File(dbPath);</span><br><span class="line">		} <span class="keyword">else</span> {</span><br><span class="line">			<span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">		}</span><br><span class="line">	}</span><br><span class="line">	</span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> SQLiteDatabase <span class="title">openOrCreateDatabase</span><span class="params">(String name, <span class="keyword">int</span> mode, SQLiteDatabase.CursorFactory factory)</span> </span>{</span><br><span class="line">		<span class="keyword">int</span> flags = SQLiteDatabase.CREATE_IF_NECESSARY | SQLiteDatabase.NO_LOCALIZED_COLLATORS;</span><br><span class="line">		<span class="keyword">return</span> SQLiteDatabase.openDatabase(getDatabasePath(name).getAbsolutePath(), factory, flags, <span class="keyword">null</span>);</span><br><span class="line">	}</span><br><span class="line">	</span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> SQLiteDatabase <span class="title">openOrCreateDatabase</span><span class="params">(String name, <span class="keyword">int</span> mode, SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler)</span> </span>{</span><br><span class="line">		<span class="keyword">int</span> flags = SQLiteDatabase.CREATE_IF_NECESSARY | SQLiteDatabase.NO_LOCALIZED_COLLATORS;</span><br><span class="line">		<span class="keyword">return</span> SQLiteDatabase.openDatabase(getDatabasePath(name).getAbsolutePath(), factory, flags, errorHandler);</span><br><span class="line">	}</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
</li>
</ul>
<figure class="highlight haxe"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// &#x91CD;&#x5199;&#x4F20;&#x5165;DaoMaster.DevOpenHelper&#x7684;Context&#xFF0C;&#x5373;&#x6539;&#x53D8;&#x6570;&#x636E;&#x5E93;&#x7684;&#x8DEF;&#x5F84;</span></span><br><span class="line">DatabaseContext databaseContext = <span class="keyword">new</span> <span class="type">DatabaseContext</span>(<span class="built_in">this</span>, DB_PATH);</span><br><span class="line">DaoMaster.OpenHelper helper = <span class="keyword">new</span> <span class="type">DaoMaster</span>.DevOpenHelper(databaseContext, VOD_DB, <span class="literal">null</span>);</span><br><span class="line">&#x5176;&#x4ED6;&#x7C7B;&#x4F3C;&#x6253;&#x5F00;&#x5185;&#x90E8;&#x6570;&#x636E;&#x5E93;</span><br></pre></td></tr></tbody></table></figure>
<ul>
<li><p><strong>&#x6CE8;&#x610F;&#xFF1A;</strong></p>
<ul>
<li>DaoMaster.DevOpenHelper&#x5728;&#x6570;&#x636E;&#x5E93;&#x5347;&#x7EA7;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4F1A;&#x5220;&#x9664;&#x6240;&#x6709;&#x7684;&#x8868;&#xFF0C;&#x53EA;&#x80FD;&#x7528;&#x4E8E;Debug&#x8C03;&#x8BD5;&#xFF0C;&#x6B63;&#x5F0F;&#x9879;&#x76EE;&#x9700;&#x8981;&#x5C01;&#x88C5;&#x5904;&#x7406;&#xFF0C;GreenDao&#x5347;&#x7EA7;&#x8BF7;&#x53C2;&#x8003;&#xFF1A;<a href="https://github.com/yuweiguocn/GreenDaoUpgradeHelper" target="_blank" rel="noopener">GreenDaoUpgradeHelper</a></li>
<li>&#x5982;&#x679C;GreenDao&#x60F3;&#x4F7F;&#x7528;<strong>&#x6253;&#x5F00;&#x591A;&#x4E2A;&#x6570;&#x636E;&#x5E93;</strong>&#xFF0C;&#x53EF;&#x4EE5;&#x521B;&#x5EFA;&#x591A;&#x4E2A;DaoMaster.OpenHelper&#x548C;DaoSession&#xFF1B;&#x540C;&#x65F6;&#x91CD;&#x5199;onCreate&#x65B9;&#x6CD5;&#xFF0C;&#x5426;&#x5219;&#x6BCF;&#x4E2A;&#x6570;&#x636E;&#x5E93;&#x7684;&#x8868;&#x662F;&#x4E00;&#x6837;&#x7684;&#x3002;&#x4F8B;&#x5982;&#xFF1A;<figure class="highlight haxe"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">DaoMaster.OpenHelper helper = <span class="keyword">new</span> <span class="type">DaoMaster</span>.OpenHelper(<span class="built_in">this</span>, DB_NAME) {</span><br><span class="line">		@Override</span><br><span class="line">		<span class="keyword">public</span> void onCreate(Database db) {</span><br><span class="line">			ConfigDao.createTable(db, <span class="literal">false</span>);</span><br><span class="line">			MemberDao.createTable(db, <span class="literal">false</span>);</span><br><span class="line">		}</span><br><span class="line">	};</span><br><span class="line">	mDaoSession = <span class="keyword">new</span> <span class="type">DaoMaster</span>(helper.getWritableDatabase()).<span class="keyword">new</span><span class="type">Session</span>();</span><br><span class="line">	</span><br><span class="line">	DaoMaster.OpenHelper encryptedHelper = <span class="keyword">new</span> <span class="type">DaoMaster</span>.OpenHelper(<span class="built_in">this</span>, ENCRYPTED_DB_NAME) {</span><br><span class="line">		@Override</span><br><span class="line">		<span class="keyword">public</span> void onCreate(Database db) {</span><br><span class="line">			AccountDao.createTable(db, <span class="literal">false</span>);</span><br><span class="line">		}</span><br><span class="line">	};</span><br><span class="line">	mEncryptedDaoSession = <span class="keyword">new</span> <span class="type">DaoMaster</span>(encryptedHelper.getEncryptedWritableDb(getUniquePseudoID())).<span class="keyword">new</span><span class="type">Session</span>();</span><br></pre></td></tr></tbody></table></figure>
</li>
</ul>
</li>
</ul>
<h2 id="&#x589E;&#x5220;&#x6539;&#x67E5;"><a href="#&#x589E;&#x5220;&#x6539;&#x67E5;" class="headerlink" title="&#x589E;&#x5220;&#x6539;&#x67E5;"></a>&#x589E;&#x5220;&#x6539;&#x67E5;</h2><ul>
<li><p>&#x4F7F;&#x7528;Dao&#x64CD;&#x4F5C;&#x65F6;&#xFF0C;&#x6570;&#x636E;&#x5E93;&#x91CC;&#x5FC5;&#x987B;&#x6709;<strong>&#x4E3B;&#x952E;</strong>&#xFF0C;&#x64CD;&#x4F5C;&#x624D;&#x4F1A;&#x6210;&#x529F;&#xFF1B;&#x5426;&#x5219;&#x64CD;&#x4F5C;&#x65E0;&#x6548;&#x6216;&#x8FBE;&#x4E0D;&#x5230;&#x9884;&#x671F;&#x7684;&#x7ED3;&#x679C;</p>
</li>
<li><p>GreenDao&#x6709;&#x4E00;&#x4E2A;&#x7F13;&#x5B58;&#x673A;&#x5236;&#xFF0C;&#x5373;&#x628A;&#x7528;&#x6237;&#x63D2;&#x5165;&#xFF0C;&#x66F4;&#x6539;&#x6216;&#x67E5;&#x627E;&#x7684;&#x5B9E;&#x4F53;&#x4FDD;&#x5B58;&#x5728;&#x5185;&#x5B58;&#x4E2D;&#xFF0C;&#x5F53;&#x7528;&#x6237;&#x4E0B;&#x4E00;&#x6B21;&#x67E5;&#x627E;&#x65F6;&#x5148;&#x4ECE;&#x5185;&#x5B58;&#x4E2D;&#x67E5;&#x627E;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x5B58;&#x5728;&#x518D;&#x4ECE;&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x67E5;&#x627E;&#xFF0C;&#x6E05;&#x9664;&#x7F13;&#x5B58;&#x4F7F;&#x7528;&#xFF1A;<code>DaoSession.clear()</code></p>
</li>
<li><p>&#x5982;&#x679C;&#x6CA1;&#x6709;&#x4E3B;&#x952E;&#xFF0C;&#x5219;&#x53EA;&#x80FD;&#x4F7F;&#x7528;Sql&#x8BED;&#x53E5;&#x64CD;&#x4F5C;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x53EF;&#x4EE5;&#x53C2;&#x8003;&#xFF1A;<a href="http://tiimor.cn/Android%E9%BB%84%E9%87%91%E7%AF%87-SQLite%E6%95%B0%E6%8D%AE%E5%BA%93/">Android&#x9EC4;&#x91D1;&#x7BC7;-SQLite&#x6570;&#x636E;&#x5E93;</a></p>
</li>
</ul>
<h3 id="Dao&#x589E;&#x52A0;"><a href="#Dao&#x589E;&#x52A0;" class="headerlink" title="Dao&#x589E;&#x52A0;"></a>Dao&#x589E;&#x52A0;</h3><figure class="highlight processing"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">long</span>     insert(T entity)  <span class="comment">// &#x63D2;&#x5165;&#x6307;&#x5B9A;&#x5B9E;&#x4F53;</span></span><br><span class="line"><span class="keyword">void</span>     insertInTx(T... entities)</span><br><span class="line"><span class="keyword">void</span>     insertInTx(java.lang.Iterable&lt;T&gt; entities)</span><br><span class="line"><span class="keyword">void</span>     insertInTx(java.lang.Iterable&lt;T&gt; entities, <span class="built_in">boolean</span> setPrimaryKey)</span><br><span class="line"><span class="keyword">long</span>     insertWithoutSettingPk(T entity)  <span class="comment">// &#x63D2;&#x5165;&#x6307;&#x5B9A;&#x5B9E;&#x4F53;&#xFF0C;&#x65E0;&#x4E3B;&#x952E;</span></span><br><span class="line"><span class="keyword">long</span>     insertOrReplace(T entity)  <span class="comment">// &#x63D2;&#x5165;&#x6216;&#x66FF;&#x6362;&#x6307;&#x5B9A;&#x5B9E;&#x4F53;</span></span><br><span class="line"><span class="keyword">void</span>     insertOrReplaceInTx(T... entities)</span><br><span class="line"><span class="keyword">void</span>     insertOrReplaceInTx(java.lang.Iterable&lt;T&gt; entities)</span><br><span class="line"><span class="keyword">void</span>     insertOrReplaceInTx(java.lang.Iterable&lt;T&gt; entities, <span class="built_in">boolean</span> setPrimaryKey)</span><br><span class="line"><span class="keyword">void</span>     <span class="built_in">save</span>(T entity)  <span class="comment">// &#x4F9D;&#x8D56;&#x6307;&#x5B9A;&#x7684;&#x4E3B;&#x952E;&#x63D2;&#x5165;&#x6216;&#x4FEE;&#x6539;&#x5B9E;&#x4F53;</span></span><br><span class="line"><span class="keyword">void</span>     saveInTx(T... entities)</span><br><span class="line"><span class="keyword">void</span>     saveInTx(java.lang.Iterable&lt;T&gt; entities)</span><br></pre></td></tr></tbody></table></figure>
<h3 id="Dao&#x5220;&#x9664;"><a href="#Dao&#x5220;&#x9664;" class="headerlink" title="Dao&#x5220;&#x9664;"></a>Dao&#x5220;&#x9664;</h3><figure class="highlight dart"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">void</span>     deleteAll()  <span class="comment">// &#x5220;&#x9664;&#x6240;&#x6709;</span></span><br><span class="line"><span class="keyword">void</span>     delete(T entity)  <span class="comment">// &#x5220;&#x9664;&#x6307;&#x5B9A;&#x7684;&#x5B9E;&#x4F53;</span></span><br><span class="line"><span class="keyword">void</span>     deleteInTx(T... entities)</span><br><span class="line"><span class="keyword">void</span>     deleteInTx(java.lang.<span class="built_in">Iterable</span>&lt;T&gt; entities)</span><br><span class="line"><span class="keyword">void</span>     deleteByKey(K key)  <span class="comment">// &#x5220;&#x9664;&#x6307;&#x5B9A;&#x4E3B;&#x952E;&#x5BF9;&#x5E94;&#x7684;&#x5B9E;&#x4F53;</span></span><br><span class="line"><span class="keyword">void</span>     deleteByKeyInTx(K... keys)</span><br><span class="line"><span class="keyword">void</span>     deleteByKeyInTx(java.lang.<span class="built_in">Iterable</span>&lt;K&gt; keys)</span><br></pre></td></tr></tbody></table></figure>
<h3 id="Dao&#x4FEE;&#x6539;"><a href="#Dao&#x4FEE;&#x6539;" class="headerlink" title="Dao&#x4FEE;&#x6539;"></a>Dao&#x4FEE;&#x6539;</h3><figure class="highlight lisp"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">void     update(<span class="name">T</span> entity)</span><br><span class="line">void     updateInTx(<span class="name">T</span>... entities)</span><br><span class="line">void     updateInTx(<span class="name">java</span>.lang.Iterable&lt;T&gt; entities)</span><br></pre></td></tr></tbody></table></figure>
<h3 id="Dao&#x67E5;&#x8BE2;"><a href="#Dao&#x67E5;&#x8BE2;" class="headerlink" title="Dao&#x67E5;&#x8BE2;"></a>Dao&#x67E5;&#x8BE2;</h3><figure class="highlight pf"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">java.util.List<span class="variable">&lt;T&gt;</span>     <span class="built_in">load</span>All()</span><br><span class="line">T     <span class="built_in">load</span>(K key)</span><br><span class="line">T     <span class="built_in">load</span>ByRowId(long rowId)</span><br></pre></td></tr></tbody></table></figure>
<h3 id="QueryBuilder&#x67E5;&#x8BE2;"><a href="#QueryBuilder&#x67E5;&#x8BE2;" class="headerlink" title="QueryBuilder&#x67E5;&#x8BE2;"></a>QueryBuilder&#x67E5;&#x8BE2;</h3><figure class="highlight dts"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">QueryBuilder<span class="params">&lt;T&gt;</span>     queryBuilder()  <span class="comment">// Dao</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// QueryBuilder</span></span><br><span class="line">QueryBuilder<span class="params">&lt;T&gt;</span>     where(WhereCondition cond, WhereCondition... condMore)  <span class="comment">// &#x6761;&#x4EF6;&#xFF0C;AND &#x8FDE;&#x63A5;</span></span><br><span class="line">QueryBuilder<span class="params">&lt;T&gt;</span>     whereOr(WhereCondition cond1, WhereCondition cond2, WhereCondition... condMore)  <span class="comment">// &#x6761;&#x4EF6;&#xFF0C;OR &#x8FDE;&#x63A5;</span></span><br><span class="line">QueryBuilder<span class="params">&lt;T&gt;</span>     distinct()  <span class="comment">// &#x53BB;&#x91CD;&#xFF0C;&#x4F8B;&#x5982;&#x4F7F;&#x7528;&#x8054;&#x5408;&#x67E5;&#x8BE2;&#x65F6;</span></span><br><span class="line">QueryBuilder<span class="params">&lt;T&gt;</span>     limit(int limit)  <span class="comment">// &#x9650;&#x5236;&#x8FD4;&#x56DE;&#x6570;</span></span><br><span class="line">QueryBuilder<span class="params">&lt;T&gt;</span>     offset(int offset)  <span class="comment">// &#x504F;&#x79FB;&#x7ED3;&#x679C;&#x8D77;&#x59CB;&#x4F4D;&#xFF0C;&#x914D;&#x5408;limit(int)&#x4F7F;&#x7528;</span></span><br><span class="line">QueryBuilder<span class="params">&lt;T&gt;</span>     orderAsc(Property... properties)  <span class="comment">// &#x6392;&#x5E8F;&#xFF0C;&#x5347;&#x5E8F;</span></span><br><span class="line">QueryBuilder<span class="params">&lt;T&gt;</span>     orderDesc(Property... properties)  <span class="comment">// &#x6392;&#x5E8F;&#xFF0C;&#x964D;&#x5E8F;</span></span><br><span class="line">QueryBuilder<span class="params">&lt;T&gt;</span>     orderCustom(Property property, java.lang.String customOrderForProperty)  <span class="comment">// &#x6392;&#x5E8F;&#xFF0C;&#x81EA;&#x5B9A;&#x4E49;</span></span><br><span class="line">QueryBuilder<span class="params">&lt;T&gt;</span>     orderRaw(java.lang.String rawOrder)  <span class="comment">// &#x6392;&#x5E8F;&#xFF0C;SQL &#x8BED;&#x53E5;</span></span><br><span class="line">QueryBuilder<span class="params">&lt;T&gt;</span>     preferLocalizedStringOrder()  <span class="comment">// &#x672C;&#x5730;&#x5316;&#x5B57;&#x7B26;&#x4E32;&#x6392;&#x5E8F;&#xFF0C;&#x7528;&#x4E8E;&#x52A0;&#x5BC6;&#x6570;&#x636E;&#x5E93;&#x65E0;&#x6548;</span></span><br><span class="line">QueryBuilder<span class="params">&lt;T&gt;</span>     stringOrderCollation(java.lang.String stringOrderCollation)  <span class="comment">// &#x81EA;&#x5B9A;&#x4E49;&#x5B57;&#x7B26;&#x4E32;&#x6392;&#x5E8F;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E0D;&#x533A;&#x5206;&#x5927;&#x5C0F;&#x5199;</span></span><br><span class="line"></span><br><span class="line">WhereCondition     and(WhereCondition cond1, WhereCondition cond2, WhereCondition... condMore)  <span class="comment">// &#x6761;&#x4EF6;&#xFF0C;AND &#x8FDE;&#x63A5;</span></span><br><span class="line">WhereCondition     or(WhereCondition cond1, WhereCondition cond2, WhereCondition... condMore)  <span class="comment">// &#x6761;&#x4EF6;&#xFF0C;OR &#x8FDE;&#x63A5;</span></span><br></pre></td></tr></tbody></table></figure>
<p>&#x793A;&#x4F8B;<br></p><figure class="highlight css"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">mAccountDao</span><span class="selector-class">.queryBuilder</span>()<span class="selector-class">.orderDesc</span>(<span class="selector-tag">Properties</span><span class="selector-class">.Date</span>)<span class="selector-class">.limit</span>(1)<span class="selector-class">.unique</span>()</span><br></pre></td></tr></tbody></table></figure><p></p>
<h3 id="DaoSession&#x5F02;&#x6B65;&#x64CD;&#x4F5C;"><a href="#DaoSession&#x5F02;&#x6B65;&#x64CD;&#x4F5C;" class="headerlink" title="DaoSession&#x5F02;&#x6B65;&#x64CD;&#x4F5C;"></a>DaoSession&#x5F02;&#x6B65;&#x64CD;&#x4F5C;</h3><figure class="highlight less"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">DaoSession</span>()<span class="selector-class">.startAsyncSession</span>()<span class="selector-class">.runInTx</span>(new Runnable() {</span><br><span class="line"></span><br><span class="line">    <span class="variable">@Override</span></span><br><span class="line">    public void run() {</span><br><span class="line">        <span class="comment">// insert</span></span><br><span class="line">        <span class="comment">// delete</span></span><br><span class="line">        <span class="comment">// update</span></span><br><span class="line">		<span class="comment">// query</span></span><br><span class="line">    }</span><br><span class="line">});</span><br><span class="line"><span class="selector-tag">DaoSession</span><span class="selector-class">.startAsyncSession</span>()<span class="selector-class">.insertInTx</span></span><br><span class="line"><span class="selector-tag">DaoSession</span><span class="selector-class">.startAsyncSession</span>()<span class="selector-class">.deleteInTx</span></span><br><span class="line"><span class="selector-tag">DaoSession</span><span class="selector-class">.startAsyncSession</span>()<span class="selector-class">.updateInTx</span></span><br><span class="line"><span class="selector-tag">DaoSession</span><span class="selector-class">.startAsyncSession</span>()<span class="selector-class">.insertInTx</span></span><br><span class="line"><span class="selector-tag">DaoSession</span><span class="selector-class">.startAsyncSession</span>()<span class="selector-class">.insertOrReplaceInTx</span></span><br></pre></td></tr></tbody></table></figure>
<h3 id="DaoSession&#x589E;&#x5220;&#x6539;&#x67E5;"><a href="#DaoSession&#x589E;&#x5220;&#x6539;&#x67E5;" class="headerlink" title="DaoSession&#x589E;&#x5220;&#x6539;&#x67E5;"></a>DaoSession&#x589E;&#x5220;&#x6539;&#x67E5;</h3><figure class="highlight stylus"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// DaoSession &#x7684;&#x65B9;&#x6CD5;&#x8F6C;&#x6362;&#x6210; Dao &#x7684;&#x5BF9;&#x5E94;&#x65B9;&#x6CD5;&#x6267;&#x884C;</span></span><br><span class="line">&lt;T&gt; long     insert(T entity)</span><br><span class="line">&lt;T&gt; long     insertOrReplace(T entity)</span><br><span class="line">&lt;T&gt; void     delete(T entity)</span><br><span class="line">&lt;T&gt; void     deleteAll(java<span class="selector-class">.lang</span><span class="selector-class">.Class</span>&lt;T&gt; entityClass)</span><br><span class="line">&lt;T&gt; void     update(T entity)</span><br><span class="line">&lt;T,K&gt; T     load(java<span class="selector-class">.lang</span><span class="selector-class">.Class</span>&lt;T&gt; entityClass, K key)</span><br><span class="line">&lt;T,K&gt; java<span class="selector-class">.util</span><span class="selector-class">.List</span>&lt;T&gt;     loadAll(java<span class="selector-class">.lang</span><span class="selector-class">.Class</span>&lt;T&gt; entityClass)</span><br><span class="line">&lt;T&gt; QueryBuilder&lt;T&gt;     queryBuilder(java<span class="selector-class">.lang</span><span class="selector-class">.Class</span>&lt;T&gt; entityClass)</span><br><span class="line">&lt;T,K&gt; java<span class="selector-class">.util</span><span class="selector-class">.List</span>&lt;T&gt;     queryRaw(java<span class="selector-class">.lang</span><span class="selector-class">.Class</span>&lt;T&gt; entityClass, java<span class="selector-class">.lang</span><span class="selector-class">.String</span> where, java<span class="selector-class">.lang</span><span class="selector-class">.String</span>... selectionArgs)</span><br><span class="line">&lt;T&gt; void     refresh(T entity)</span><br></pre></td></tr></tbody></table></figure>
<h3 id="Query&#x91CD;&#x590D;&#x67E5;&#x8BE2;"><a href="#Query&#x91CD;&#x590D;&#x67E5;&#x8BE2;" class="headerlink" title="Query&#x91CD;&#x590D;&#x67E5;&#x8BE2;"></a>Query&#x91CD;&#x590D;&#x67E5;&#x8BE2;</h3><figure class="highlight glsl"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// QueryBuilder</span></span><br><span class="line">Query&lt;T&gt;     build()</span><br><span class="line">CursorQuery     buildCursor()</span><br><span class="line">CountQuery&lt;T&gt;     buildCount()</span><br><span class="line">DeleteQuery&lt;T&gt;     buildDelete()</span><br><span class="line"></span><br><span class="line"><span class="comment">// Query</span></span><br><span class="line"><span class="comment">// &#x8BBE;&#x7F6E;&#x67E5;&#x8BE2;&#x53C2;&#x6570;&#xFF0C;&#x4ECE; 0 &#x5F00;&#x59CB;</span></span><br><span class="line">Query&lt;T&gt;     setParameter(<span class="type">int</span> <span class="keyword">index</span>, java.lang.Object parameter)</span><br><span class="line">Query&lt;T&gt;     setParameter(<span class="type">int</span> <span class="keyword">index</span>, java.lang.Boolean parameter)</span><br><span class="line">Query&lt;T&gt;     setParameter(<span class="type">int</span> <span class="keyword">index</span>, java.util.Date parameter)</span><br><span class="line"><span class="type">void</span>     setLimit(<span class="type">int</span> limit)  <span class="comment">// &#x9650;&#x5236;&#x8FD4;&#x56DE;&#x6570;</span></span><br><span class="line"><span class="type">void</span>     setOffset(<span class="type">int</span> <span class="keyword">offset</span>)  <span class="comment">// &#x504F;&#x79FB;&#x7ED3;&#x679C;&#x8D77;&#x59CB;&#x4F4D;&#xFF0C;&#x914D;&#x5408;limit(int)&#x4F7F;&#x7528;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// Query &#x7ED1;&#x5B9A;&#x7EBF;&#x7A0B;&#xFF0C;&#x6267;&#x884C;&#x975E;&#x672C;&#x7EBF;&#x7A0B;&#x7684; Query &#x629B;&#x5F02;&#x5E38;&#xFF0C;&#x8C03;&#x7528;&#x83B7;&#x53D6;&#x672C;&#x7EBF;&#x7A0B; Query</span></span><br><span class="line">Query&lt;T&gt;     forCurrentThread()  <span class="comment">// &#x83B7;&#x53D6;&#x672C;&#x7EBF;&#x7A0B; Query</span></span><br></pre></td></tr></tbody></table></figure>
<h3 id="&#x67E5;&#x8BE2;&#x7ED3;&#x679C;"><a href="#&#x67E5;&#x8BE2;&#x7ED3;&#x679C;" class="headerlink" title="&#x67E5;&#x8BE2;&#x7ED3;&#x679C;"></a>&#x67E5;&#x8BE2;&#x7ED3;&#x679C;</h3><figure class="highlight dts"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// QueryBuilder&#x3001;Query</span></span><br><span class="line">T     unique()  <span class="comment">// &#x8FD4;&#x56DE;&#x552F;&#x4E00;&#x7ED3;&#x679C;&#x6216;&#x8005; null</span></span><br><span class="line">T     uniqueOrThrow()  <span class="comment">// &#x8FD4;&#x56DE;&#x552F;&#x4E00;&#x975E;&#x7A7A;&#x7ED3;&#x679C;&#xFF0C;&#x5982;&#x679C; null &#x5219;&#x629B;&#x5F02;&#x5E38;</span></span><br><span class="line">java.util.List<span class="params">&lt;T&gt;</span>     list()  <span class="comment">// &#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#x96C6;&#x8FDB;&#x5185;&#x5B58;</span></span><br><span class="line"><span class="comment">// &#x61D2;&#x52A0;&#x8F7D;&#xFF0C;&#x987B;&#x5728; try/finally &#x4EE3;&#x7801;&#x4E2D;&#x5173;&#x95ED;&#x3002;</span></span><br><span class="line">LazyList<span class="params">&lt;T&gt;</span>     listLazy()  <span class="comment">// &#x7B2C;&#x4E00;&#x6B21;&#x4F7F;&#x7528;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#x96C6;&#xFF0C;&#x6240;&#x6709;&#x6570;&#x636E;&#x4F7F;&#x7528;&#x540E;&#x4F1A;&#x81EA;&#x52A8;&#x5173;&#x95ED;</span></span><br><span class="line">LazyList<span class="params">&lt;T&gt;</span>     listLazyUncached()  <span class="comment">// &#x8FD4;&#x56DE;&#x865A;&#x62DF;&#x7ED3;&#x679C;&#x96C6;&#xFF0C;&#x6570;&#x636E;&#x5E93;&#x8BFB;&#x53D6;&#x4E0D;&#x7F13;&#x5B58;</span></span><br><span class="line">CloseableListIterator<span class="params">&lt;T&gt;</span>     listIterator()  <span class="comment">// &#x61D2;&#x52A0;&#x8F7D;&#x6570;&#x636E;&#x8FED;&#x4EE3;&#x5668;&#xFF0C;&#x4E0D;&#x7F13;&#x5B58;&#xFF0C;&#x6240;&#x6709;&#x6570;&#x636E;&#x4F7F;&#x7528;&#x540E;&#x4F1A;&#x81EA;&#x52A8;&#x5173;&#x95ED;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// QueryBuilder&#x3001;CountQuery</span></span><br><span class="line">long     count()  <span class="comment">// &#x83B7;&#x53D6;&#x7ED3;&#x679C;&#x6570;&#x91CF;</span></span><br></pre></td></tr></tbody></table></figure>
<h1 id="&#x6DF7;&#x6DC6;"><a href="#&#x6DF7;&#x6DC6;" class="headerlink" title="&#x6DF7;&#x6DC6;"></a>&#x6DF7;&#x6DC6;</h1><p>&#x5728;&#x6DF7;&#x6DC6;&#x6587;&#x4EF6;proguard-rules.pro&#x4E2D;&#x6DFB;&#x52A0;</p>
<figure class="highlight scala"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">### greenDAO <span class="number">3</span></span><br><span class="line">-keepclassmembers <span class="class"><span class="keyword">class</span> <span class="title">*</span> <span class="keyword">extends</span> <span class="title">org</span>.<span class="title">greenrobot</span>.<span class="title">greendao</span>.<span class="title">AbstractDao</span> </span>{</span><br><span class="line">public static java.lang.<span class="type">String</span> <span class="type">TABLENAME</span>;</span><br><span class="line">}</span><br><span class="line">-keep <span class="class"><span class="keyword">class</span> <span class="title">**$Properties</span></span></span><br><span class="line"><span class="class"></span></span><br><span class="line"><span class="class"><span class="title">#</span> <span class="title">If</span> <span class="title">you</span> <span class="title">do</span> <span class="title">not</span> <span class="title">use</span> <span class="title">SQLCipher</span></span>:</span><br><span class="line">-dontwarn org.greenrobot.greendao.database.**</span><br><span class="line"># <span class="type">If</span> you do not use <span class="type">RxJava</span>:</span><br><span class="line">-dontwarn rx.**</span><br></pre></td></tr></tbody></table></figure>
<p><strong>@ToOne&#x3001;@ToMany&#xFF0C;1&#xFF1A;1&#x3001;1&#xFF1A;n&#x3001;n&#xFF1A;m&#x7B49;&#x591A;&#x5F20;&#x8868;&#x5173;&#x8054;&#x5F85;&#x7EED;^_^</strong></p>
<script>
        document.querySelectorAll('.github-emoji')
          .forEach(el => {
            if (!el.dataset.src) { return; }
            const img = document.createElement('img');
            img.style = 'display:none !important;';
            img.src = el.dataset.src;
            img.addEventListener('error', () => {
              img.remove();
              el.style.color = 'inherit';
              el.style.backgroundImage = 'none';
              el.style.background = 'none';
            });
            img.addEventListener('load', () => {
              img.remove();
            });
            document.body.appendChild(img);
          });
      </script>
      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>谢谢老板，请尽情用红包来蹂躏我吧！！！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/uploads/wechatpay.jpg" alt="Tiimor 微信打赏">
        <p>微信打赏</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/uploads/alipay.jpg" alt="Tiimor 支付宝打赏">
        <p>支付宝打赏</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <!-- modify by zhangwei -->
            <!-- 文章底部标签图标 -->
            <a href="/tags/Android/" rel="tag"><i class="menu-item-icon fa fa-tag fa-fw"></i>Android</a>
          
            <!-- modify by zhangwei -->
            <!-- 文章底部标签图标 -->
            <a href="/tags/SQLite/" rel="tag"><i class="menu-item-icon fa fa-tag fa-fw"></i>SQLite</a>
          
            <!-- modify by zhangwei -->
            <!-- 文章底部标签图标 -->
            <a href="/tags/GreenDao/" rel="tag"><i class="menu-item-icon fa fa-tag fa-fw"></i>GreenDao</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/Android适配器终结者？/" rel="next" title="Android适配器终结者？">
                <i class="fa fa-chevron-left"></i> Android适配器终结者？
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/Android数据库加密/" rel="prev" title="Android数据库加密">
                Android数据库加密 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      
        <div id="gitment-container"></div>
      
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/uploads/avatar.jpg" alt="Tiimor">
            
              <p class="site-author-name" itemprop="name">Tiimor</p>
              <p class="site-description motion-element" itemprop="description">安静地做一只攻城狮。</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">41</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">6</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">56</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/VeiZhang" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="http://www.weibo.com/tiimor" target="_blank" title="微博">
                      
                        <i class="fa fa-fw fa-weibo"></i>微博</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://juejin.im/user/589972d0570c3500624fd791" target="_blank" title="掘金">
                      
                        <i class="fa fa-fw fa-anchor"></i>掘金</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="http://www.jianshu.com/u/93b886580243" target="_blank" title="简书">
                      
                        <i class="fa fa-fw fa-book"></i>简书</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="http://wpa.qq.com/msgrd?v=3&uin=690393541&site=qq&menu=yes" target="_blank" title="QQ">
                      
                        <i class="fa fa-fw fa-qq"></i>QQ</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:tiimor@qq.com" target="_blank" title="邮箱">
                      
                        <i class="fa fa-fw fa-envelope"></i>邮箱</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#GreenDao介绍"><span class="nav-number">1.</span> <span class="nav-text">GreenDao介绍</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#配置"><span class="nav-number">2.</span> <span class="nav-text">配置</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#配置插件"><span class="nav-number">2.1.</span> <span class="nav-text">配置插件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#配置依赖"><span class="nav-number">2.2.</span> <span class="nav-text">配置依赖</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#基本用法"><span class="nav-number">3.</span> <span class="nav-text">基本用法</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#实体"><span class="nav-number">3.1.</span> <span class="nav-text">实体</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#注解"><span class="nav-number">3.2.</span> <span class="nav-text">注解</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#初始化"><span class="nav-number">3.3.</span> <span class="nav-text">初始化</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#增删改查"><span class="nav-number">3.4.</span> <span class="nav-text">增删改查</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Dao增加"><span class="nav-number">3.4.1.</span> <span class="nav-text">Dao增加</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Dao删除"><span class="nav-number">3.4.2.</span> <span class="nav-text">Dao删除</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Dao修改"><span class="nav-number">3.4.3.</span> <span class="nav-text">Dao修改</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Dao查询"><span class="nav-number">3.4.4.</span> <span class="nav-text">Dao查询</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#QueryBuilder查询"><span class="nav-number">3.4.5.</span> <span class="nav-text">QueryBuilder查询</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#DaoSession异步操作"><span class="nav-number">3.4.6.</span> <span class="nav-text">DaoSession异步操作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#DaoSession增删改查"><span class="nav-number">3.4.7.</span> <span class="nav-text">DaoSession增删改查</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Query重复查询"><span class="nav-number">3.4.8.</span> <span class="nav-text">Query重复查询</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#查询结果"><span class="nav-number">3.4.9.</span> <span class="nav-text">查询结果</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#混淆"><span class="nav-number">4.</span> <span class="nav-text">混淆</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2017 &mdash; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Tiimor</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a></div>




        
<div class="busuanzi-count">
  <!-- modify by zhangwei -->
  <!-- 修改不蒜子统计脚本 -->
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</div>



<script>
  	var _mtac = {};
  	(function() {
  		var mta = document.createElement("script");
  		mta.src = "https://pingjs.qq.com/h5/stats.js?v2.0.4";
  		mta.setAttribute("name", "MTAH5");
  		mta.setAttribute("sid", "500425805");

  		var s = document.getElementsByTagName("script")[0];
  		s.parentNode.insertBefore(mta, s);
  	})();
</script>


  <script type="text/javascript">
    (function() {
      var hm = document.createElement("script");
      hm.src = "//tajs.qq.com/stats?sId=61441764";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  







<!-- LOCAL: You can save these files to your site and update links -->
    
        
        <link rel="stylesheet" href="https://aimingoo.github.io/gitmint/style/default.css">
        <script src="https://aimingoo.github.io/gitmint/dist/gitmint.browser.js"></script>
    
<!-- END LOCAL -->

    

    
      <script type="text/javascript">
      function renderGitment(){
        var gitment = new Gitmint({
            <!-- modify by zhangwei -->
            <!-- 修复gitment评论页初始化错误@tiimor -->
            id: '1509784492000', 
            owner: 'VeiZhang',
            repo: 'veizhang.github.io',
            
            lang: "" || navigator.language || navigator.systemLanguage || navigator.userLanguage,
            
            oauth: {
            
            
                client_secret: '9919bc61413a89ea3eb156910d282e3103093e32',
            
                client_id: 'f08924ca58e61d6f51f4'
            }});
        gitment.render('gitment-container');
      }

      
      renderGitment();
      
      </script>
    







  




  
  
  
  <link rel="stylesheet" href="/lib/algolia-instant-search/instantsearch.min.css">

  
  
  <script src="/lib/algolia-instant-search/instantsearch.min.js"></script>
  

  <script src="/js/src/algolia-search.js?v=5.1.4"></script>



  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("7aBs9I9Y3PjoN6ueX5J3AYQW-gzGzoHsz", "kboycyzaPNAYcUW8AkF3edeW");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  
  

  

  

  

  
  <!-- modify by zhangwei -->
  <!-- 动态时间小人 -->
  <!-- modify by zhangwei -->
<!-- 动态时间小人 -->
<!-- z-index -1 表示在最底层，不能悬浮也不能点击 -->
<!-- z-index auto 可以点击 -->
<!-- z-index 9999 无限大时，总是在最上层，会影响其他悬浮框 -->
<div id="dg" style="z-index: auto; position: fixed ! important; right: 0px; top: 0px;">  
    <table width 100% style="position: absolute; width:260px; right: 0px; top: 0px;">  
		<div>
			<embed wmode="transparent" src="http://cdn.tiimor.cn/images/dynamic_time.swf" quality="high" bgcolor="#ffffff" width="160" height="70" name="honehoneclock" align="middle" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
		</div>
    </table>  
</div>
  
</body>
</html>
